<?php
SESSION_START();
include "DBConnectMenu.php";
include "funcoes.php";

$strSQL = " SELECT id_menu, descricao, pagina FROM menu ORDER BY descricao ASC ";
$Menu = execute($strSQL);

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<HTML>
	<HEAD>
		<TITLE>SRSystem</TITLE>
		<LINK rel="stylesheet" type="text/css" href="css/padrao.css"/>
		<LINK rel="stylesheet" type="text/css" href="css/jquery-ui-1.8.10.custom.css"/>
		<SCRIPT language="javascript" type="text/javascript" src="js/jquery/jquery-1.4.4.min.js"></SCRIPT>
		<SCRIPT language="javascript" type="text/javascript" src="js/jquery/jquery-ui-1.8.10.custom.min.js"></SCRIPT>
		<STYLE type="text/css">
			*{
				padding: 0;
				margin: 0;
			}
			
			.menu{
				float: left;
				width: 150px;
				height: 100%;
				-webkit-border-top-left-radius: 50px;
				-webkit-border-top-right-radius: 50px;
				-moz-border-radius-topleft: 50px;
				-moz-border-radius-topright: 50px;
				border-top-left-radius: 50px;
				border-top-right-radius: 50px;
			}
			
			.vazio{
				float: left;
				-webkit-border-radius: 50px;
				-moz-border-radius: 50px;
				border-radius: 50px;
			}
			
			.back{
				height: 90%;
				border-bottom: 1px solid red;
			}
			
			.no-bottom-border{
				-webkit-border-bottom-right-radius: 0px;
				-webkit-border-bottom-left-radius: 0px;
				-moz-border-radius-bottomright: 0px;
				-moz-border-radius-bottomleft: 0px;
				border-bottom-right-radius: 0px;
				border-bottom-left-radius: 0px;
			}
			
			<?while($linha = mysql_fetch_array($Menu)){?>
			#menu_<?echo $linha['id_menu']?>{
				position: absolute;
				<?if($linha['id_menu'] == 1){?>
				z-index: 1;
				<?}else{?>
				z-index: 0;
				<?}?>
			}
			<?}?>
		</STYLE>
		<SCRIPT type="text/javascript">
			function menu(url, id){
				parent.content.location.href = url;
				
				if(id != 0){
					parent.left.location.href = "menu_left.php?id_menu=" + id + "&pagina=" + url;
				}else{
					parent.left.location.href = "vazio.php";
				}
			}
			
			$(function(){
				$(".menu").button();
				
				$("#adm").click(function(){
					menu('adm/index_adm.php',0);
				});
			});
		</SCRIPT>
	</HEAD>
	<BODY class="ui-widget-header">
		<DIV style="width:100%;height:100%;">
			<?if ($_SESSION['usuario'] == 1){?>
			<DIV class="menu vazio" style="border-bottom: 0px;height: 90%;width: 15%; top:5%;" id="adm">
				<TABLE border="0" width="100%" cellpadding="0" cellspacing="0">
					<TR>
						<TD align="right">
							<IMG src="images/configuracoes.png" width="30" height="30" border="0"/>
						</TD>
						<TD align="left">
							&nbsp;ADM
						</TD>
					</TR>
				</TABLE>
			</DIV>
			<?
			}
			
			mysql_data_seek($Menu,0);
			$id_menu = "";
			
			while($linha = mysql_fetch_array($Menu)){
				if($id_menu == ""){
					$id_menu = Trim($linha['id_menu']);
				}else{
					$id_menu .= ','. Trim($linha['id_menu']);
				}
			?>
			<DIV class="menu back" style="border-bottom: 0px;" id="menu_<?echo $linha['id_menu']?>"><?echo $linha['descricao']?></DIV>
			<?
			}
			
			mysql_data_seek($Menu,0);
			?>
			<INPUT type="hidden" name="id_menu" id="id_menu" value="<?echo $id_menu?>" />
		</DIV>
	</BODY>
	<SCRIPT type="text/javascript" language="javascript">
		<?
		while($linha = mysql_fetch_array($Menu)){	?>
			$("#menu_<?echo $linha['id_menu']?>").click(function(){
				menu('<?echo $linha['pagina']?>', '<?echo $linha['id_menu']?>');
				$("#menu_<?echo $linha['id_menu']?>").addClass("no-bottom-border");
				$("#menu_<?echo $linha['id_menu']?>").addClass("ui-state-error");
				$("#menu_<?echo $linha['id_menu']?>").removeClass("back");
				$("#menu_<?echo $linha['id_menu']?>").css("z-index", "1");
				
				var _id_menu = document.getElementById('id_menu').value;
				_id_menu = _id_menu.split(",");
				
				for(var i=0;i<_id_menu.length;i++){
					if(_id_menu[i] != '' && _id_menu[i] != '<?echo $linha['id_menu']?>'){
						$("#menu_" + _id_menu[i]).removeClass("no-bottom-border");
						$("#menu_" + _id_menu[i]).removeClass("ui-state-error");
						$("#menu_" + _id_menu[i]).addClass("back");
						$("#menu_" + _id_menu[i]).css("z-index", "0");
					}
				}
			});
		<?
		}
		?>
		
		$(document).ready(function(){
			var _id_menu = document.getElementById('id_menu').value;
			_id_menu = _id_menu.split(",");
			
			var width = screen.width;
			width = (width*15)/100;
			
			for(var i=0;i<_id_menu.length;i++){
				$('#menu_' + _id_menu[i]).css('left', width);
				width = width + 135;
			}
		});
	</SCRIPT>
</HTML>